<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <script th:src="@{/js/jquery.min.js}"></script>
    <title>Title</title>
</head>
<body>
<table id="dg"  width="98%" height="55%" >
    <tr>
        <td align="right">
            <label>托盘编号：</label>
        </td>
        <td align="left">
            <input type="text" id="trayCode">
        </td>
    </tr>
    <tr>
        <td align="right">
            <label>单据号：</label>
        </td>
        <td align="left">
            <input type="text" id="detailId" onchange="selectByStockId()"  name="detailId" >
        </td>
    </tr>
    <tr>
        <td align="right">
            <label>物品编码：</label>
        </td>
        <td align="left">
            <input type="text" id="productId" oninput="searchProduct()">
        </td>
    </tr>

    <tr>
    <td align="right">
        <label>物品名称：</label>
    </td>
    <td align="left">
        <input type="text" id="productName">
    </td>
</tr>
    <tr>
        <td align="right">
            <label>比例号：</label>
        </td>
        <td align="left">
            <input type="text" id="price">
        </td>
    </tr>

    <tr>
        <td align="right">
            <label>数量：</label>
        </td>
        <td align="left">
            <input type="text" id="quantity">
        </td>
    </tr>
    <tr>
        <td align="right">
            <label>垛型：</label>
        </td>
        <td align="left">
            <select id="stackingId" name="stackingId">
                <option value="1">口字垛</option>
                <option value="2">日字垛</option>
                <option value="4">回字垛</option>
            </select>
        </td>
    </tr>
    <tr >
        <td align="right">
            <label>批号：</label>
        </td>
        <td align="left">
            <input type="text" id="lotNo">
        </td>
    </tr>
    <tr >
        <td align="right">
            <label>单位：</label>
        </td>
        <td align="left">
            <input type="text" id="unit">
        </td>
    </tr>

<tr >
    <td align="right">
        <label>单据号：</label>
    </td>
        <td>
            <input id="stockinId" name="stockinId" type="text">
        </td>
    </tr>
<!--    <tr hidden="hidden">-->
<!--        <td>-->
<!--            <input id="detailId" name="detailId" type="text">-->
<!--        </td>-->
<!--    </tr>-->
    <tr>
        <td align="right">
            <button id="submitbut" type="button" onclick="handon()">提交信息</button>
        </td>
        <td align="left">
            <button id="btn1" type="button" onclick="sure()">确认入库</button>
        </td>
    </tr>
</table>
<script>
    var assignquantity=0;
    function selectByStockId() {

        var detailId=document.getElementById("detailId").value;
        // var productId=document.getElementById("productId").value;
        if(detailId.substring(0,2)!="RD"){
            alert("扫码格式不正确！");
            document.getElementById("detailId").value="";
            return;
        }
        $.ajax({
            "url": "/pda/list?detailId="+detailId,
            "type": "POST",
            "dataType": "json",
            "success": function (result) {
                console.log(result)
                if(result.msg==1){
                    alert("无该单据")
                    $('#productId').attr("value","");
                    $('#productName').attr("value", "");
                    $('#lotNo').attr("value","");
                    $('#price').attr("value","");
                    $('#quantity').attr('value',"");
                    $('#stockinId').attr("value","");
                    $('#unit').attr("value","");
                    document.getElementById("detailId").value="";
                    return
                }
                console.log(result)
                $('#productId').attr("value",result.data.productId);
                $('#productName').attr("value", result.data.productName);
                $('#lotNo').attr("value",result.data.lotNo);
                $('#price').attr("value",result.data.price);
                // $('#quantity').attr('value',result.data.quantity);
                $('#quantity').attr('placeholder','还能输入"'+result.data.quantity+'"数量');
                $('#stockinId').attr("value",result.data.stockinId);
                // $('#detailId').attr("value",result.data.stockinDetailId);
                $('#unit').attr("value",result.data.unit);
                assignquantity=result.data.quantity;
                // document.getElementById("stockinDetail").value="";
            }
        });
    }

   function handon() {
       var productId = document.getElementById("productId").value;
       var productName = document.getElementById("productName").value;
       var lotNo=document.getElementById("lotNo").value;
       var trayCode = document.getElementById("trayCode").value;
       var price = document.getElementById("price").value;
       var stockinId = document.getElementById("stockinId").value;
       var quantity=document.getElementById("quantity").value;
       var stackingId=document.getElementById("stackingId").value;
       var detailId=document.getElementById("detailId").value;

       if ((detailId.length == "" || detailId.length == null)) {
           alert("单据号不能为空！");
           return;
       }
       if ((trayCode.length == "" || trayCode.length == null)) {
           alert("托盘号不能为空！");
           return;
       }
       //控制按钮多次点击
       var btn = document.getElementById('submitbut');//首先需要获取的是哪一个按钮的id
       btn.disabled = 'disabled';//只要点击就将按钮的可点击的状态更改为不可以点击的状态
       setTimeout(function () {//设置时间，多久可以改变状态为可以点击
           btn.disabled = '';
       }, 5000);

       $.post("/pda/msgSure", {
           stockinId : stockinId,
           productId : productId,
           productName : productName ,
           lotNo : lotNo,
           price : price ,
           trayCode:trayCode,
           detailId : detailId,
           quantity : quantity,
           stackingId:stackingId,
           type : 1
       }, function (result) {
           alert(result.v_resutmsg)
           window.location.reload();
           // $('#productId').attr("value","");
           // $('#productName').attr("value", "");
           // $('#lotNo').attr("value","");
           // $('#price').attr("value","");
           // $('#quantity').attr('value',"");
           // $('#stockinId').attr("value","");
           // $('#detailId').attr("value","");
           // $('#unit').attr("value","");
           // document.getElementById("stockinDetail").value="";
       }, "json");
   }

    function sure(){
        var productId = document.getElementById("productId").value;
        var productName = document.getElementById("productName").value;
        var lotNo=document.getElementById("lotNo").value;
        var trayCode = document.getElementById("trayCode").value;
        var price = document.getElementById("price").value;
        var stockinId = document.getElementById("stockinId").value;
        var quantity=document.getElementById("quantity").value;
        var stackingId=document.getElementById("stackingId").value;
        var detailId=document.getElementById("detailId").value;

        if ((detailId.length == "" || detailId.length == null)) {
            alert("单据号不能为空！");
            return;
        }
        if ((trayCode.length == "" || trayCode.length == null)) {
            alert("托盘号不能为空！");
            return;
        }
        //控制按钮多次点击
        var btn = document.getElementById('submitbut');//首先需要获取的是哪一个按钮的id
        btn.disabled = 'disabled';//只要点击就将按钮的可点击的状态更改为不可以点击的状态
        setTimeout(function () {//设置时间，多久可以改变状态为可以点击
            btn.disabled = '';
        }, 5000);

        $.post("/pda/msgSure", {
            stockinId : stockinId,
            productId : productId,
            productName : productName ,
            lotNo : lotNo,
            price : price ,
            trayCode:trayCode,
            detailId : detailId,
            quantity : quantity,
            stackingId:stackingId,
            type : 2
        }, function (result) {
            alert(result.v_resutmsg)
            window.location.reload();
            // $('#productId').attr("value","");
            // $('#productName').attr("value", "");
            // $('#lotNo').attr("value","");
            // $('#price').attr("value","");
            // $('#quantity').attr('value',"");
            // $('#stockinId').attr("value","");
            // $('#detailId').attr("value","");
            // $('#unit').attr("value","");
            // document.getElementById("stockinDetail").value="";
        }, "json");
    }
</script>
</body>
</html>